//package com.tiancheng.trade.settlement.util.queue;
//
//import lombok.extern.slf4j.Slf4j;
//import org.redisson.api.RBlockingDeque;
//import org.redisson.api.RDelayedQueue;
//import org.redisson.api.RedissonClient;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.Map;
//import java.util.concurrent.TimeUnit;
//
///**
// * @Author: likailun
// * @Description: redis实现的延迟队列
// * @Date: create in 2022/4/7 3:57 下午
// */
//@Slf4j
//@Component
//public class RedisDelayQueueUtil {
//    @Autowired
//    private RedissonClient redissonClient;
//
//    public <T> void addDelayQueue(T value, long delay, TimeUnit timeUnit, String queueCode) {
//        try {
//            RBlockingDeque<Object> blockingDeque = redissonClient.getBlockingDeque(queueCode);
//            RDelayedQueue<Object> delayedQueue = redissonClient.getDelayedQueue(blockingDeque);
//            delayedQueue.offer(value, delay, timeUnit);
//        } catch (RuntimeException e) {
//            log.error("(添加延时队列失败) {}", e.getMessage());
//            throw new RuntimeException("(添加延时队列失败)");
//        }
//    }
//
//    /**
//     * 获取延迟队列
//     *
//     * @param queueCode
//     * @param <T>
//     * @return
//     * @throws InterruptedException
//     */
//    public <T> T getDelayQueue(String queueCode) throws InterruptedException {
//        RBlockingDeque<Map> blockingDeque = redissonClient.getBlockingDeque(queueCode);
//        T value = (T) blockingDeque.take();
//        return value;
//    }
//}
